Skip to content

Delay import of ssl in pex.fetcher.#2417

Merged
jsirois merged 8 commits intopex-tool:mainfrom
jsirois:issues/2415
Jun 5, 2024
Merged

Delay import of ssl in pex.fetcher.#2417
jsirois merged 8 commits intopex-tool:mainfrom
jsirois:issues/2415

Conversation

@jsirois
Copy link
Member

@jsirois jsirois commented Jun 5, 2024

This acts as an affordance for users of the gevent monkey patch system,
avoiding warnings about potential imports of ssl pre-monkey-patching.

Fixes #2415

@jsirois jsirois requested review from benjyw and huonw June 5, 2024 01:30
stderr_fp.flush()
stderr_fp.seek(0)
stderr = stderr_fp.read()
assert b"MonkeyPatchWarning: Monkey-patching ssl after ssl " not in stderr, stderr.decode(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure at this commit looks like:

>           assert b"MonkeyPatchWarning: Monkey-patching ssl after ssl " not in stderr, stderr.decode(
                "utf-8"
            )
E           AssertionError: /tmp/pytest-of-jsirois/pytest-52/test_gevent_monkeypatch0/pex_root/unzipped_pexes/d0b0f145223b1d7c391f024af1f2baa4bebd475f/app.py:2: MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016. Modules that had direct imports (NOT patched): ['pex.fetcher (/tmp/pytest-of-jsirois/pytest-52/test_gevent_monkeypatch0/pex_root/unzipped_pexes/d0b0f145223b1d7c391f024af1f2baa4bebd475f/.bootstrap/pex/fetcher.py)'].
E               monkey.patch_all()

install_command =
docs,check,typecheck,py{py27,py35,py36,py37,py38,py39,py310,27,35,36,37,38,39,310,311,312,313}: \
python -m pip install {opts} {toxinidir} {packages}
python -m pip install {opts} -e {toxinidir} {packages}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was needed to ensure non-stale Pex on the test sys.path. Toggling back and forth between the aggressive and lazy import ssl I noticed the Pex state was sticky. Fallout from #2408 just noticed now.

@jsirois jsirois merged commit 1a02d54 into pex-tool:main Jun 5, 2024
@jsirois jsirois deleted the issues/2415 branch June 5, 2024 22:05
jsirois added a commit to jsirois/pex that referenced this pull request Jun 6, 2024
Previously the test could hang when the log fifo was closed by the
gunicorn server before the port was written to the log; now it fails.

Follow up to pex-tool#2417 which introduced the test and led to observed hangs
in CI.
jsirois added a commit that referenced this pull request Jun 7, 2024
Previously the test could hang when the log fifo was closed by the
gunicorn server before the port was written to the log; now it fails
when this happens.

Follow up to #2417 which introduced the test and led to observed hangs
in CI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monkey patch warning when using PEX to run a gunicorn app

3 participants